import Router from 'koa-router'
import { Models } from '../../../../common/typings/model'
import { Success } from '../../../../core/HttpException'
import Mysql from '../../../../core/Mysql'
import Auth from '../../../../middlewares/Auth'
import validator from '../../../../middlewares/validator'
import getBoardById from '../../../../common/apiValidate/lowCode/board/query'
import Config from '../../../../config/Config'

const router = new Router({
  prefix: `${Config.api_prefix}lowCode/board`,
})

/*
 * 查询看板
 * @return
 */
router.get('/query', Auth.verifyTokenPermission, validator(getBoardById), async (ctx: Models.Ctx) => {
  const id = Number(ctx.request.query.id)
  const res = await Mysql.command(`
  SELECT
    *
    FROM
      board
    WHERE
      id = ${id}
  `)
  throw new Success(res.results[0])
})

export default router
